home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / 8080bw.c < prev    next >
C/C++ Source or Header  |  2000-05-20  |  4KB  |  164 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12.  
  13. static int shift_data1,shift_data2,shift_amount;
  14.  
  15.  
  16. WRITE_HANDLER( invaders_shift_amount_w )
  17. {
  18.     shift_amount = data;
  19. }
  20.  
  21. WRITE_HANDLER( invaders_shift_data_w )
  22. {
  23.     shift_data2 = shift_data1;
  24.     shift_data1 = data;
  25. }
  26.  
  27.  
  28. #define SHIFT  (((((shift_data1 << 8) | shift_data2) << (shift_amount & 0x07)) >> 8) & 0xff)
  29.  
  30.  
  31. READ_HANDLER( invaders_shift_data_r )
  32. {
  33.     return SHIFT;
  34. }
  35.  
  36. READ_HANDLER( invaders_shift_data_rev_r )
  37. {
  38.     int    ret = SHIFT;
  39.  
  40.     ret = ((ret & 0x01) << 7)
  41.         | ((ret & 0x02) << 5)
  42.         | ((ret & 0x04) << 3)
  43.         | ((ret & 0x08) << 1)
  44.         | ((ret & 0x10) >> 1)
  45.         | ((ret & 0x20) >> 3)
  46.         | ((ret & 0x40) >> 5)
  47.         | ((ret & 0x80) >> 7);
  48.  
  49.     return ret;
  50. }
  51.  
  52. READ_HANDLER( invaders_shift_data_comp_r )
  53. {
  54.     return SHIFT ^ 0xff;
  55. }
  56.  
  57.  
  58. int invaders_interrupt(void)
  59. {
  60.     static int count;
  61.  
  62.     count++;
  63.  
  64.     if (count & 1)
  65.         return 0x00cf;  /* RST 08h */
  66.     else
  67.         return 0x00d7;  /* RST 10h */
  68. }
  69.  
  70. /****************************************************************************
  71.     Extra / Different functions for Boot Hill                (MJC 300198)
  72. ****************************************************************************/
  73.  
  74. READ_HANDLER( boothill_shift_data_r )
  75. {
  76.     if (shift_amount < 0x10)
  77.         return invaders_shift_data_r(0);
  78.     else
  79.         return invaders_shift_data_rev_r(0);
  80. }
  81.  
  82. /* Grays binary again! */
  83.  
  84. static const int boothill_controller_table[8] =
  85. {
  86.     0x00, 0x40, 0x60, 0x70, 0x30, 0x10, 0x50, 0x50
  87. };
  88.  
  89. READ_HANDLER( boothill_port_0_r )
  90. {
  91.     return (input_port_0_r(0) & 0x8f) | boothill_controller_table[input_port_3_r(0) >> 5];
  92. }
  93.  
  94. READ_HANDLER( boothill_port_1_r )
  95. {
  96.     return (input_port_1_r(0) & 0x8f) | boothill_controller_table[input_port_4_r(0) >> 5];
  97. }
  98.  
  99.  
  100. static const int gunfight_controller_table[8] =
  101. {
  102.     0x10, 0x50, 0x70, 0x30, 0x20, 0x60, 0x40, 0x00
  103. };
  104.  
  105. READ_HANDLER( gunfight_port_0_r )
  106. {
  107.     return (input_port_0_r(0) & 0x8f) | (gunfight_controller_table[input_port_3_r(0) >> 5]);
  108. }
  109.  
  110. READ_HANDLER( gunfight_port_1_r )
  111. {
  112.     return (input_port_1_r(0) & 0x8f) | (gunfight_controller_table[input_port_4_r(0) >> 5]);
  113. }
  114.  
  115. /*
  116.  * Space Encounters uses rotary controllers on input ports 0 & 1
  117.  * each controller responds 0-63 for reading, with bit 7 as
  118.  * fire button.
  119.  *
  120.  * The controllers return Grays binary, so I use a table
  121.  * to translate my simple counter into it!
  122.  */
  123.  
  124. static const int graybit6_controller_table[64] =
  125. {
  126.     0  , 1  , 3  , 2  , 6  , 7  , 5  , 4  ,
  127.     12 , 13 , 15 , 14 , 10 , 11 , 9  , 8  ,
  128.     24 , 25 , 27 , 26 , 30 , 31 , 29 , 28 ,
  129.     20 , 21 , 23 , 22 , 18 , 19 , 17 , 16 ,
  130.     48 , 49 , 51 , 50 , 54 , 55 , 53 , 52 ,
  131.     60 , 61 , 63 , 62 , 58 , 59 , 57 , 56 ,
  132.     40 , 41 , 43 , 42 , 46 , 47 , 45 , 44 ,
  133.     36 , 37 , 39 , 38 , 34 , 35 , 33 , 32
  134. };
  135.  
  136. READ_HANDLER( spcenctr_port_0_r )
  137. {
  138.     return (input_port_0_r(0) & 0xc0) + (graybit6_controller_table[input_port_0_r(0) & 0x3f] ^ 0x3f);
  139. }
  140.  
  141. READ_HANDLER( spcenctr_port_1_r )
  142. {
  143.     return (input_port_1_r(0) & 0xc0) + (graybit6_controller_table[input_port_1_r(0) & 0x3f] ^ 0x3f);
  144. }
  145.  
  146.  
  147. READ_HANDLER( seawolf_port_1_r )
  148. {
  149.     return (input_port_0_r(0) & 0xe0) + graybit6_controller_table[input_port_0_r(0) & 0x1f];
  150. }
  151.  
  152.  
  153. static int desertgu_controller_select;
  154.  
  155. READ_HANDLER( desertgu_port_1_r )
  156. {
  157.     return readinputport(desertgu_controller_select ? 0 : 2);
  158. }
  159.  
  160. WRITE_HANDLER( desertgu_controller_select_w )
  161. {
  162.     desertgu_controller_select = data & 0x08;
  163. }
  164.